package com.example.myprogressview;

import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {
    private RelativeLayout container;
    private MyProgressView myProgressView;
    private TextView title1;
    private TextView title2;

    private TextView title3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        //初始化组件
        container = findViewById(R.id.container);
        myProgressView = findViewById(R.id.visit_progress_view);
        title1 = findViewById(R.id.title1);
        title2 = findViewById(R.id.title2);
        title3 = findViewById(R.id.title3);
        //设置进度条
        setupProgressView();

    }

    /**
     * 初始化进度条组件
     */
    private void setupProgressView() {
        container.post(new Runnable() {
            @Override
            public void run() {
                int height = container.getMeasuredHeight();
                Log.i("mjt", "容器的最终高度 --> " + height);
                ViewGroup.LayoutParams layoutParams = myProgressView.getLayoutParams();
                layoutParams.height = height;
                myProgressView.setLayoutParams(layoutParams);
                myProgressView.setHeight(height);
                //设置进度条圆点位置
                int padding = container.getPaddingTop();
                float y1 = (title1.getTop() + title1.getBottom() - 2 * padding) >> 1;
                float y2 = (title2.getTop() + title2.getBottom() - 2 * padding) >> 1;
                float y3 = (title3.getTop() + title3.getBottom() - 2 * padding) >> 1;
                myProgressView.setStartY(y1);
                myProgressView.setCirclePositions(new float[]{y1, y2, y3});
            }
        });
        //设置进度
        myProgressView.setProgress(3);
    }

}